package informationGet.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.whu.zj.R;
import com.whu.zj.UIHandler;

import informationGet.dto.Points;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * 显示图片
 * Created by Administrator on 2016/3/16.
 */
public class ShowImage extends UIHandler.BaseActivity {

    ImageView img_photo;
    TextView tv_content;

    Points points = new Points();

    PhotoViewAttacher mAttacher;
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.defalut_img) //设置图片在下载期间显示的图片
            .showImageForEmptyUri(R.drawable.defalut_img)//设置图片Uri为空或是错误的时候显示的图片
            .showImageOnFail(R.drawable.defalut_img)  //设置图片加载/解码过程中错误时候显示的图片
//    .cacheInMemory(true)//设置下载的图片是否缓存在内存中
            .cacheOnDisc(true)//设置下载的图片是否缓存在SD卡中
            .considerExifParams(true)  //是否考虑JPEG图像EXIF参数（旋转，翻转）
            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示
            .bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//
            .resetViewBeforeLoading(true)//设置图片在下载前是否重置，复位
            .displayer(new RoundedBitmapDisplayer(20))//是否设置为圆角，弧度为多少
            .displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
            .build();//构建完成

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pointimage);
        initview();
        initdata();
    }

    private void initdata() {
        points = (Points) getIntent().getSerializableExtra("points");
        String content = points.getMessage();
        tv_content.setText(content == null?"":content);
        if (content == null)
            tv_content.setVisibility(View.GONE);

        ImageLoader imageLoader = ImageLoader.getInstance();
        String host = getResources().getString(R.string.basicIP);
        imageLoader.displayImage("http://" + host + "/mobilepoint/" + points.getFileName(), img_photo, options, new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                super.onLoadingComplete(imageUri, view, loadedImage);
                mAttacher.update();
            }
        });

    }

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    };

    private void initview() {

        img_photo = (ImageView) findViewById(R.id.id_img_photo);
        tv_content = (TextView) findViewById(R.id.id_tv_content);
        mAttacher = new PhotoViewAttacher(img_photo);

    }


}
